package com.aperos.android15;

import java.util.Date;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.OverlayItem;

public class Bar extends OverlayItem {
	private Integer id;
	private String name;
	private String address;
	private Double priceBeer;
	private Double priceCocktail;
	private Integer happyHourBeginHour;
	private Integer happyHourBeginMinute;
	private Integer happyHourEndHour;
	private Integer happyHourEndMinute;
	private Double priceBeerHappyHour;
	private Double priceCocktailHappyHour;
	private int latitudeE6;
	private int longitudeE6;
	private boolean inHappyHour;
	
	
	public Bar(int id, int latitudeE6, int longitudeE6, String name, String address, Double priceBeer, Double priceCocktail,
			Integer happyHourBeginHour, Integer happyHourBeginMinute, Integer happyHourEndHour, 
			Integer happyHourEndMinute, Double priceBeerHappyHour, Double priceCocktailHappyHour) {
		super(new GeoPoint(latitudeE6, longitudeE6), name, address);
		this.id = id;
		this.name = name;
		this.address = address;
		this.priceBeer = priceBeer;
		this.priceCocktail = priceCocktail;
		this.happyHourBeginHour = happyHourBeginHour;
		this.happyHourBeginMinute = happyHourBeginMinute;
		this.happyHourEndHour = happyHourEndHour;
		this.happyHourEndMinute = happyHourEndMinute;
		this.priceBeerHappyHour = priceBeerHappyHour;
		this.priceBeerHappyHour = priceBeerHappyHour;
		this.priceCocktailHappyHour = priceCocktailHappyHour;
		this.latitudeE6 = latitudeE6;
		this.longitudeE6 = longitudeE6;
	}
	
	public Bar(int latitudeE6, int longitudeE6, String name, String address, Double priceBeer, Double priceCocktail,
			Integer happyHourBeginHour, Integer happyHourBeginMinute, Integer happyHourEndHour, 
			Integer happyHourEndMinute, Double priceBeerHappyHour, Double priceCocktailHappyHour) {
		super(new GeoPoint(latitudeE6, longitudeE6), name, address);
		this.name = name;
		this.address = address;
		this.priceBeer = priceBeer;
		this.priceCocktail = priceCocktail;
		this.happyHourBeginHour = happyHourBeginHour;
		this.happyHourBeginMinute = happyHourBeginMinute;
		this.happyHourEndHour = happyHourEndHour;
		this.happyHourEndMinute = happyHourEndMinute;
		this.priceBeerHappyHour = priceBeerHappyHour;
		this.priceCocktailHappyHour = priceCocktailHappyHour;
		this.latitudeE6 = latitudeE6;
		this.longitudeE6 = longitudeE6;
	}
	
	
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public Double getPriceBeer() {
		return priceBeer;
	}
	public void setPriceBeer(Double priceBeer) {
		this.priceBeer = priceBeer;
	}
	public int getLatitudeE6() {
		return latitudeE6;
	}
	public void setLatitudeE6(int latitudeE6) {
		this.latitudeE6 = latitudeE6;
	}
	public int getLongitudeE6() {
		return longitudeE6;
	}
	public void setLongitudeE6(int longitudeE6) {
		this.longitudeE6 = longitudeE6;
	}
	
	public String toString() {
		return "id -> " + id + ", name -> " + name + ", address -> " + address + ", price -> " + priceBeer;
	}

	public Double getPriceCocktail() {
		return priceCocktail;
	}

	public void setPriceCocktail(Double priceCocktail) {
		this.priceCocktail = priceCocktail;
	}

	public Integer getHappyHourBeginHour() {
		return happyHourBeginHour;
	}

	public void setHappyHourBeginHour(Integer happyHourBeginHour) {
		this.happyHourBeginHour = happyHourBeginHour;
	}

	public Integer getHappyHourBeginMinute() {
		return happyHourBeginMinute;
	}

	public void setHappyHourBeginMinute(Integer happyHourBeginMinute) {
		this.happyHourBeginMinute = happyHourBeginMinute;
	}

	public Integer getHappyHourEndHour() {
		return happyHourEndHour;
	}

	public void setHappyHourEndHour(Integer happyHourEndHour) {
		this.happyHourEndHour = happyHourEndHour;
	}

	public Integer getHappyHourEndMinute() {
		return happyHourEndMinute;
	}

	public void setHappyHourEndMinute(Integer happyHourEndMinute) {
		this.happyHourEndMinute = happyHourEndMinute;
	}

	public Double getPriceBeerHappyHour() {
		return priceBeerHappyHour;
	}

	public void setPriceBeerHappyHour(Double priceBeerHappyHour) {
		this.priceBeerHappyHour = priceBeerHappyHour;
	}

	public Double getPriceCocktailHappyHour() {
		return priceCocktailHappyHour;
	}

	public void setPriceCocktailHappyHour(Double priceCocktailHappyHour) {
		this.priceCocktailHappyHour = priceCocktailHappyHour;
	}

	public boolean isInHappyHour() {
		if (this.getHappyHourBeginHour() == null || this.getHappyHourBeginMinute() == null
				|| this.getHappyHourEndHour() == null || this.getHappyHourEndMinute() == null) {
			inHappyHour = false;
			return inHappyHour;
		}
		
		Date date = new Date();
		int time = date.getHours() * 100 + date.getMinutes();
		int time2 = time + 2400;
		int beginTime = this.getHappyHourBeginHour() * 100 + this.getHappyHourBeginMinute();
		int endTime = this.getHappyHourEndHour() * 100 + this.getHappyHourEndMinute();
		
		if (endTime < beginTime) {
			endTime += 2400;
		} 
		
		if ((time >= beginTime && time <= endTime) || (time2 >= beginTime && time2 <= endTime)) {
			inHappyHour = true;
		} else {
			inHappyHour = false;
		}
		
		return inHappyHour;
		
	}

	public void setInHappyHour(boolean inHappyHour) {
		this.inHappyHour = inHappyHour;
	}
	
	
}
